package palette;

import java.awt.Color;
import java.beans.PropertyVetoException;
import javax.swing.JDesktopPane;
import cuShapes.ShapeList;
import actionHandlers.*;


@SuppressWarnings("serial")
public class CanvasManager extends JDesktopPane{

	private static CanvasManager inst = null;
	private static final int xPosition = 30, yPosition = 30;
	private static int windowCount =0;
	
	public static CanvasManager getInst(){
		if(inst == null){
			inst = new CanvasManager();
		}
		return inst;
	}
	
	/**
	 * Constructor
	 */
	CanvasManager(){
		putClientProperty("JDesktopPane.dragMode", "live");
		setBackground(Color.gray);
	}
	
	public void addNewCanvas(){
		addNewCanvas("Canvas " + (windowCount+1));
	}
	
	public void addNewCanvas(String name)
	{
		DrawingWindow c = new DrawingWindow(name);
		c.setVisible(true);
		c.addInternalFrameListener(new SelectedCanvasListener());
		try {
			c.setLocation(xPosition*windowCount, yPosition*windowCount++);
			inst.add(c);
			c.setSelected(true);
		} catch (PropertyVetoException e) { e.printStackTrace(); }
	}
		
	public void addNewBuilder(String name)
	{
		BuilderWindow b = new BuilderWindow(name);
		b.setVisible(true);
		try {
			b.setLocation(xPosition*windowCount-1, yPosition*windowCount++);
			inst.add(b);
			b.setSelected(true);
		} catch (PropertyVetoException e) { e.printStackTrace(); }
	}
	
	public ShapeList getShapeList() {
		return ((CanvasWindow) (inst.getSelectedFrame())).getShapeList();
	}
}
